import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: tao
 * Date: 2023-11-09
 * Time: 22:56
 */

/**
 * 232用栈实现队列
 * https://leetcode.cn/problems/implement-queue-using-stacks/description/
 */
class MyQueue {
    private Stack<Integer> s1;//输入栈
    private Stack<Integer> s2;//输出栈

    public MyQueue() {
        s1 = new Stack<>();
        s2 = new Stack<>();
    }

    public void push(int x) {
        //入输入栈
        s1.push(x);
    }

    public int pop() {
        if(s2.empty()) {
            //把输入栈s1全部入到输出栈s2中
            while(!s1.empty()) {
                s2.push(s1.pop());
            }
        }
        //输出栈出栈
        return s2.pop();
    }

    public int peek() {
        if(s2.empty()) {
            //把输入栈s1全部入到输出栈s2中
            while(!s1.empty()) {
                s2.push(s1.pop());
            }
        }
        //peek栈出栈
        return s2.peek();
    }

    public boolean empty() {
        return s1.empty() && s2.empty();
    }
}
public class Solution {

}
